<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link type="text/css" rel="stylesheet" href="layui/css/layui.css"/>
		<script type="text/javascript" src="layui/layui.js"></script>
	</head>
	<body>
		<form id="addUser" class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>用户名</label>
				<div class="layui-input-inline">
					<input  type="text" id="userName" placeholder="请输入用户名"
						lay-verify = "required" name="userName" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>密码</label>
				<div class="layui-input-inline">
					<input  type="text" id="pwd" name="pwd" placeholder="请输入密码"
						lay-verify = "required" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="addUser">提交</button>
				<button type="reset" class="layui-btn" lay-submit>取消</button>
				</div>
			</div>
		</form>
		
		<script>
		layui.use(['form','layer'],function(){
			var form = layui.form,$ = layui.$,layer = layui.layer;
				
			
			// 表单按钮在监听的时候    updateUser按钮后面的（lay-filter事件名字）
				form.on('submit(addUser)',function(data){
					//layer.msg("提交动作");
					// post把表单数据发送到服务器端
					// 使用序列化的时候 input的name属性当成参数名字  ，值是参数值
					var str = $("#addUser").serialize();
					$.post(
						"http://localhost:8080/fearless/UserAdminServlet?req=userAdd",
						str,
						function(res){
							if(res.success){
						   	 //先得到当前iframe层的索引
							var index = parent.layer.getFrameIndex(window.name); 
							//再执行关闭 
							parent.layer.close(index);  
							//关闭父级页面的表格
							parent.layui.table.reload('table');
						   }else{
						   	layer.alert("添加失败");
						   }
						},
						"json"
					)
					
					return false;// 停留在这里
				})
				
			})
			
		</script>
		
	</body>
</html>
